﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Zekiah.GeoCommons.ArcGIS.Framework
{
    public class Win32Api
    {
        [System.Runtime.InteropServices.DllImport("user32.dll")]
        public static extern bool SetWindowLong(int hWnd, int index, int NewInt);

        //http://msdn.microsoft.com/en-us/library/bb776419(VS.85).aspx
        [System.Runtime.InteropServices.DllImport("shell32.dll", EntryPoint = "FindExecutable")]
        public static extern int FindExecutableA(
          string lpFile, string lpDirectory, StringBuilder lpResult);

        public static string GetExecutable(string filename)
        {
            try
            {
                int result = 0;
                string retval = "";
                StringBuilder buffer = new StringBuilder(1024);
                result = FindExecutableA(filename, string.Empty, buffer);
                if (result >= 32)
                {
                    retval = buffer.ToString();
                }
                return retval;
            }
            catch
            {
                return "";
            }
        }
    }
}
